package com.kyzh.core.pager.weal.address

import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import com.google.gson.Gson
import com.gushenge.core.base.activity.BaseActivity
import com.gushenge.core.impls.UserImpl
import com.gushenge.core.listeners.ResultListener
import com.gushenge.core.toast
import com.kyzh.core.R
import com.kyzh.core.utils.aesEcb
import kotlinx.android.synthetic.main.act_addressedit.*

class AddressNewActivity : BaseActivity(), ResultListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.act_addressedit)
        initUi()
    }

    private fun initUi() {
        (commit.background as GradientDrawable).cornerRadius = 222f
        titleView.setText(getString(R.string.myAddress))
        commit.setOnClickListener {
            val map = HashMap<String,String>()
            val name  = name.text.toString().trim()
            val phone  = phone.text.toString().trim()
            val address  = uaddress.text.toString().trim()
            val aliAccount  = aliAccount.text.toString().trim()
            val aliName  = aliName.text.toString().trim()
            if (name.isNotEmpty()&& phone.isNotEmpty()&&address.isNotEmpty()&&aliAccount.isNotEmpty()&&aliName.isNotEmpty()) {
                map["consignee"] = name
                map["mobile"] = phone
                map["uaddress"] = address
                map["bank_id"] = aliAccount
                map["bank_user"] = aliName
                map["moren"] = if (switcher.isChecked)"1" else "0"
                val value = aesEcb(Gson().toJson(map))
                UserImpl.addAddress(value,this)
            }else{
                getString(R.string.pleaseSelectHaveEmpty).toast()
            }

        }


    }
    override fun success(message: Any) {
        message.toast()
        finish()
    }

    override fun error(error: String) {
        error.toast()
    }

}
